package com.samphanie.auiu.biz.goods

import android.graphics.Color
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.samphanie.auiu.R
import com.samphanie.auiu.common.ui.component.BaseAppBindingActivity
import com.samphanie.auiu.databinding.ActivityGoodsListBinding
import com.samphanie.auiu.library.utils.AuiuStatusBar.setStatusBar
import com.samphanie.auiu.route.AuiuRoute


@Route(path = "/goods/list")
class GoodsListActivity : BaseAppBindingActivity<ActivityGoodsListBinding>() {

    @JvmField
    @Autowired
    var cateTitle: String = ""

    @JvmField
    @Autowired
    var cateId: String = ""

    @JvmField
    @Autowired
    var subCateId: String = ""

    override fun getLayoutId(): Int {
        return R.layout.activity_goods_list
    }

    private val FRAGMENT_TAG = "GOODS_LIST_FRAGMENT_TAG"

    override fun initialize(savedInstanceState: Bundle?) {
        setStatusBar(this, true, translucent =  false)
        AuiuRoute.inject(this)

        var fragment = supportFragmentManager.findFragmentByTag(FRAGMENT_TAG)
        if (fragment == null) {
            fragment = GoodsListFragment.newInstance(cateId, subCateId)
        }
        val ft = supportFragmentManager.beginTransaction()
        if (!fragment.isAdded) {
            ft.add(R.id.container, fragment, FRAGMENT_TAG)
        }
        ft.show(fragment).commitNowAllowingStateLoss()

        binding.cateTitle.text = cateTitle
        binding.actionBack.setOnClickListener {
            backPress(savedInstanceState)
        }
    }
}